<?php

class AbTableDraw
{

public static $instance; 

public static function getInstance()
	{
		//echo "<div id=register-box>";
        if(self::$instance==null)
		  self::$instance=new AbTableDraw();
	//   echo "</div>";	  
		return  self::$instance;
	   
    
    }
    
      function DrawSelectDays($count,$NAME)//especificar los campos que deben de aparecer 
    {
        $select="";$i=1;
        ?>        
        <label><?php echo $NAME;?>
        <select name="DayAct" class="input_pulldown">
        <?php
        while($i<$count){      
            $select=$select."<option value=".$i."> $i ";
            $i=$i+1;} 
        echo $select."</option>\n";
        ?>
        </select>       
        </label>
        </br>
    <?php
    }
    
    
    function DrawDays($id){
        
          $first = "SELECT  pack_has_tour.DateBegTour, pack_has_tour.DateEndTour FROM pack_has_tour LEFT JOIN  pack_has_tour_has_guidetc ON pack_has_tour.idPackTour = pack_has_tour_has_guidetc.pack_has_tour_idPackTour 
        WHERE ((idPackTourGui =$id))";
        
        $dates[]="";
        $query = CModelo::getInstance()->getData($first);
        //var_dump ($query);
        foreach($query as $r=>$c){
            $table0 = $c;
            foreach($table0 as $r2 => $c2){
              $dates[]=$c2;
            }
            
        }
        
        
        $que = "Select DATEDIFF ('$dates[2]','$dates[1]')";
  
        $query = CModelo::getInstance()->getData($que);
        //var_dump ($query);
        foreach($query as $r=>$c){
            $table0 = $c;
            foreach($table0 as $r2 => $c2){
              $valor = $c2;
            }
            
        }
        
        echo $valor;
    }	

function DrawTable($title,$table,$campos,$id_t)//obligatorio ID como campo inicial
    {
 
                                                                                                                                                                                                                                                                                              
    $qu="select ";
    $i = 0;
    $i = 0;
    foreach($campos as $id=>$valor)
    {
    $qu=$qu."$id,";
    }
    $qu=substr($qu,0,strlen($qu)-1);



    $qu=$qu. " FROM guidetc_has_actividades
    LEFT JOIN  `viv`.`pack_has_tour_has_guidetc` ON  `guidetc_has_actividades`.`idPackTourGui` =  `pack_has_tour_has_guidetc`.`idPackTourGui` 
    LEFT JOIN  `viv`.`actividades` ON  `guidetc_has_actividades`.`actividades_idAct` =  `actividades`.`idAct` 
    WHERE ((`pack_has_tour_has_guidetc`.`idPackTourGui` =$id_t))";

//    echo "$qu";
    
    echo "<div id='content_area_user_title'>";
    echo "<h2> $title</h2>";
    echo "</div>";


    echo	"<form>";						
    echo "<form id='filter-form'>Buscar en las lista de actividades: <input name='filter' id='filter' value='' maxlength='30' size='30' type='text'></form><br>";
    echo "</form>";
   
    echo "<div class='usersettings_statistics'>"; 
 


    echo "<table class='food_planner'>";
    
      echo "<thead>";
    
    echo "<tr>";
      //$width=10;    
     foreach($campos as $id=>$valor){
    
    echo "<th>$valor</th>";
    //$width=$width+10;
    }
    echo "</tr>";    
    echo "</thead>";
    
    echo "<tbody><tr style='display: table-row;'>";

     //echo "<table> <tbody>";


  
   

    
    // $qu="select*from $table";
    $table=CModelo::getInstance()->getData($qu);
//var_dump($table);
    $cont=0;
    $ruta=CConfig::getInstance()->rutalocal."/MDGuideData/MDAB";
    
    
    foreach($table as $campo => $valor)
    { 



$cont=$cont+1;
if($cont%2){




echo "<tr class='odd'>";
$i="";$cont=0;
foreach($valor as $id=>$val)
{ if($cont==0){$i=$val;}

echo "<td width='10%'>$val</td>";$cont=$cont+1;
}
/*---------------------------------------------------------------------------*/
// las referencias debbden de ser modificadas deacuerdo al directorio
//
/*---------------------------------------------------------------------------*/
echo "<td> <a href='$ruta/ABRegistro.php?codigo=$i&idg=$id_t&action=1'>Editar</a> </td>";
echo "<td><a href='/modificar.php?codigo=$i'>Eliminar</a> </td>";

echo "</tr>";
}
else
{

echo "<tr class='even'> ";
$i2="";$cont2=0;
foreach($valor as $id => $val)
{ if($cont2==0){$i2=$val;}
echo "<td width='10%'>$val </td>";$cont2=$cont2+1;
}
echo "<td> <a href='$ruta/ABRegistro.php?codigo=$i&idg=$id_t&action=1'>Editar</a> </td>";
echo "<td><a href='/modificar.php?codigo=$i2'>Eliminar</a> </td>";
echo "</tr>";
}

}
echo "</td></tr></tbody></table><br><br>";


echo "</div>";

} 



}
?>